#import "CustomTabBarItem.h"
 
NSString *const CustomTabBarItemAttributeTitle = @"CustomTabBarItemAttributeTitle";
NSString *const CustomTabBarItemAttributeNormalImageName = @"CustomTabBarItemAttributeNormalImageName";
NSString *const CustomTabBarItemAttributeSelectedImageName = @"CustomTabBarItemAttributeSelectedImageName";
NSString *const CustomTabBarItemAttributeType = @"CustomTabBarItemAttributeType";
 
@implementation CustomTabBarItem
 
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if (self) {
        [self config];
    }
    
    return self;
}
 
- (instancetype)init {
    self = [super init];
    
    if (self) {
        [self config];
    }
    
    return self;
}
 
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    
    if (self) {
        [self config];
    }
    
    return self;
}
 
- (void)config {
    /**
     UIButton.Configuration是一个新的结构体，
     它指定按钮及其内容的外观和行为。它有许多与按钮外观和内容相关的属性，如cornerStyle、baseForegroundColor、baseBackgroundColor、buttonSize、title、image、subtitle、titlePadding、imagePadding、contentInsets、imagePlacement等。
     */
    self.adjustsImageWhenHighlighted = NO;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
 
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.titleLabel sizeToFit];
    CGSize titleSize = self.titleLabel.frame.size;
 
    CGSize imageSize = [self imageForState:UIControlStateNormal].size;
 
    if (imageSize.width != 0 && imageSize.height != 0) {
        /**image布局为image底部距离lable顶部距离为5*/
        
        CGFloat imageViewCenterY = CGRectGetHeight(self.frame)/2+10;
                
        self.imageView.center = CGPointMake(CGRectGetWidth(self.frame) / 2-30, imageViewCenterY);
        
    } else {
        CGPoint imageViewCenter = self.imageView.center;
                imageViewCenter.x = CGRectGetWidth(self.frame) / 2;
                imageViewCenter.y = (CGRectGetHeight(self.frame) - titleSize.height) / 2;
                self.imageView.center = imageViewCenter;
    }
    /**lable距离底部是3*/
    CGPoint labelCenter = CGPointMake(CGRectGetMaxX(self.imageView.frame)+20, CGRectGetMaxY(self.imageView.frame)-20);
    self.titleLabel.center = labelCenter;
    
}
 
@end
